package com.atguigu.xml;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Node;
import org.dom4j.io.SAXReader;

import java.util.List;

/**
 * Date:2020/9/4
 * Author:ybc
 * Description:
 */
public class TestXPath {

    public static void main(String[] args) throws DocumentException {

        SAXReader reader = new SAXReader();
        Document document = reader.read("day05_xml/user.xml");
        //若通过Xpath获取单个元素
        /*Node node = document.selectSingleNode("/user/userInfo/username");
        System.out.println(node.getText());*/
        //若通过Xpath获取的元素有多个
        List list = document.selectNodes("/user/userInfo/username");
        for (Object o : list) {
            Node node = (Node) o;
            System.out.println(node.getText());
        }

    }

}
